-
Notifications
You must be signed in to change notification settings - Fork 45
Add ability to enable/ disable SSR #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Deploying redwood-sdk-docs with
|
Latest commit: |
ac8a605
|
Status: | ✅ Deploy successful! |
Preview URL: | https://79ed0b64.redwood-sdk-docs.pages.dev |
Branch Preview URL: | https://pp-add-ssr-flag.redwood-sdk-docs.pages.dev |
sdk/src/runtime/lib/router.ts
Outdated
* @param options.ssr - Disable sever side rendering for all these routes. This only allow client side rendering`, which requires `rscPayload` to be enabled. | ||
*/ | ||
options: { | ||
rscPayload: boolean; | ||
} = { rscPayload: true }, | ||
ssr: boolean; | ||
} = { rscPayload: true, ssr: true }, | ||
): Route<T>[] { | ||
const documentMiddleware: RouteMiddleware<T> = ({ rw }) => { | ||
rw.Document = Document; | ||
rw.rscPayload = options.rscPayload; | ||
rw.ssr = options.ssr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only relevant changes.
let html: ReadableStream<any>; | ||
|
||
if (rw.ssr) { | ||
html = await transformRscToHtmlStream({ | ||
stream: rscPayloadStream1, | ||
Document: rw.Document, | ||
requestInfo: requestInfo, | ||
}); | ||
} else { | ||
const emptyRscStream = renderToRscStream({ | ||
node: React.createElement(React.Fragment, null, null), | ||
actionResult: undefined, | ||
onError, | ||
}); | ||
html = await transformRscToHtmlStream({ | ||
stream: emptyRscStream, | ||
Document: rw.Document, | ||
requestInfo: requestInfo, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converts RSC to HTML or, not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah, ok! So we return just the shell for that page, clever!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧠
This PR adds the ability to toggle server-side rendering. ```tsx render(Document, [ // routes ], { ssr: false, rscPayload: true, }) ```
Fixes #515 |
@justinvdm I'm seeing a hydration error with this new flag in my test-repo. Is there something else I need to configure besides the flag on the route render? |
This PR adds the ability to toggle server-side rendering.